package com.estate.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.estate.pojo.Bespoke;
import com.estate.pojo.Project;
import com.estate.service.bespoke.BespokeService;
import com.estate.service.project.ProjectService;

@Controller
public class BespokeController {
	@Autowired
	private BespokeService bespokeService;//预约业务层
	
	@Autowired
	private ProjectService projectService;//项目业务层
	
	//进入预约排号页面
	@RequestMapping(value="/doReservationNumber")
	public String test2(){
		return "Thymeleaf/reservationNumber";
	}
	
	//查询预约排号
	@RequestMapping(value="/reservationNumber")
	@ResponseBody
	public Object reservationNumber(@RequestParam(value="projectId",defaultValue="0")Integer projectId,
									@RequestParam(value="keyword",defaultValue="")String keyword){
		List<Bespoke> bespokes=null;
		List<Project> projects=null;
		Map<String, Object> map = new HashMap<String,Object>();
		try {
			bespokes=bespokeService.getBespokeAndUser(projectId,keyword);//查询全部预约信息
			projects=projectService.getAllProject();//查询全部项目
			map.put("projects", projects);
			map.put("bespokes", bespokes);
			map.put("projectId", projectId);//保存下拉列表id
			map.put("keyword", keyword);//保存关键字
		} catch (Exception e) {
			e.printStackTrace();
		}
		return JSONArray.toJSONString(map);
	}
	
	
	
	@RequestMapping(value="/subscription")
	public String test3(){
		return "/Thymeleaf/Subscription";
	}
}
